package com.xl.cloud.resp;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @Author XiangLiang
 * @Since 2024/9/11 10:04
 * @Description: ResultData类
 */
@Data
@Accessors(chain = true)
public class ResultData<T> {
    /**
     * 结果状态,具体状态码参见枚举类ReturnCodeEnum
     */
    private String code;

    private String message;

    private T data;

    private long timeStamp;

    public ResultData() {
        this.timeStamp = System.currentTimeMillis();
    }

    public static <T> ResultData<T> success(T data) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(ReturnCodeEnum.RC200.getCode());
        resultData.setMessage(ReturnCodeEnum.RC200.getMessage());
        resultData.setData(data);
        return resultData;
    }

    public static <T> ResultData<T> fail(String code, String message) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(code);
        resultData.setMessage(message);

        return resultData;
    }

}
